//
//  NSString+KSURLEncoded.m
//  gif
//
//  Created by 薛辉 on 8/3/15.
//  Copyright (c) 2015 kuaishou. All rights reserved.
//

#import "NSString+KSURLEncoded.h"

@implementation NSString (KSURLEncoded)

- (NSString *)ks_URLEncodedStringWithCFStringEncoding:(CFStringEncoding)encoding charactersToBeEscaped:(NSString *)characters
{
    return (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef)self, NULL, (__bridge CFStringRef)characters , encoding);
}

- (NSString *)ks_URLEncodedStringWithCFStringEncoding:(CFStringEncoding)encoding
{
    return [self ks_URLEncodedStringWithCFStringEncoding:encoding charactersToBeEscaped:@"￼=,!$&'()*+;@?\n\"<>#\t :/\\"];
}

- (NSString *)ks_URLEncodedString
{
    return [self ks_URLEncodedStringWithCFStringEncoding:kCFStringEncodingUTF8];
}

- (NSString *)ks_URLDecodedString
{
    NSString *result = (NSString *)CFBridgingRelease(CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault,
                                                                                                             (CFStringRef)self,
                                                                                                             CFSTR(""),
                                                                                                             kCFStringEncodingUTF8));
    return result;
}

@end
